package org.weasel.tree;

import java.sql.Time;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

/**
 * This class provides the treeviewer with the correct images and labels.
 * @author Plack
 *
 */
public class TreeLabelProvider implements ILabelProvider {
	private final Image userstory = new Image(Display.getCurrent(), getClass().getResourceAsStream("/icons/userstory.gif"));
	private final Image exp_userstory = new Image(Display.getCurrent(), getClass().getResourceAsStream("/icons/userstory_spikecard.gif"));
	private final Image finished_exp_userstory = new Image(Display.getCurrent(), getClass().getResourceAsStream("/icons/userstory_spikecard_finished.gif"));
	private final Image finished_userstory = new Image(Display.getCurrent(), getClass().getResourceAsStream("/icons/userstory_finished.gif"));
	private final Image folder = new Image(Display.getCurrent(), getClass().getResourceAsStream("/icons/folder.gif"));

	public Image getImage(Object element) {
		if(element instanceof TreeObjectUserStory) {
			TreeObjectUserStory to_userStory = (TreeObjectUserStory) element;
			boolean isStoryFinished = !to_userStory.getUserStory().getUsedTime().equals(Time.valueOf("00:00:00"));
			boolean isStoryExperimental = to_userStory.getUserStory().isExperimental(); 
			if(isStoryFinished && isStoryExperimental) {
				return finished_exp_userstory;
			}else if(isStoryExperimental){
				return exp_userstory;
			} else if(isStoryFinished) {
				return finished_userstory;
			} else {
				return userstory;
			}
		} else {
			return folder;
		}
	}

	public String getText(Object element) {
		return ((TreeObject)element).getName();
	}

	public void addListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub
		
	}

	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	public boolean isLabelProperty(Object element, String property) {
		// TODO Auto-generated method stub
		return false;
	}

	public void removeListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub
		
	}

}
